package com.bw.a2207a.view

import android.content.Intent
import com.blankj.utilcode.util.ToastUtils
import com.bw.a2207a.R
import com.bw.a2207a.base.BaseActivity2
import com.bw.a2207a.databinding.ActivityRegisterBinding
import com.bw.a2207a.viewmodel.RegisterViewModel

class RegisterActivity : BaseActivity2<ActivityRegisterBinding, RegisterViewModel>(
    R.layout.activity_register,
    RegisterViewModel()
) {
    override fun initData() {
        viewModel.registerLiveData.observe(this) {
            ToastUtils.showShort(it.message)
            if (it.code == 200) {
                val intent = Intent(this@RegisterActivity, LoginActivity::class.java)
                intent.putExtra("name", it.data.username)
                intent.putExtra("pass", it.data.password)
                startActivity(intent)
                finish()
            }
        }
    }

    override fun initView() {

        binding.btn.setOnClickListener {
            //组装参数
            val map = HashMap<String, String>()
            map["username"] = binding.etUsername.text.toString()
            map["password"] = binding.etPassword.text.toString()
            map["repassword"] = binding.etRepassword.text.toString()

            viewModel.register(map)

        }
    }

}